/**
 * 找到包含对应 classname 的最近父节点
 *
 * @param node
 * @param classname
 */
export function closest(node: HTMLElement, classname: string): HTMLElement | undefined {
  if (node.classList && node.classList.length) {
    const hasClass = node.classList.contains(classname)

    if (hasClass) {
      return node
    } else {
      if (node.parentNode) {
        return closest(node.parentNode as HTMLElement, classname)
      }
    }
  } else if (node.parentNode) {
    return closest(node.parentNode as HTMLElement, classname)
  }
}